class List {
    constructor() {
        this.getdata()
        this.loginStatus()
    }
    // 获取列表数据
    getdata() {
        let html = ""
        axios.get('http://localhost:8888/goods/list').then(({
            data,
            status
        }) => {
            console.log(data, status);
            if (status != 200) return
            if (data.code == 1) {
                // 将数据渲染到页面中
                data.list.forEach(ele => {
                    html += `<li class="sk_goods" data-id="${ele.goods_id}">
                <a href="detail.html?id=${ele.goods_id}"><img src="${ele.img_big_logo}" alt=""></a>
                <h5 class="sk_goods_title">${ele.tatle}</h5>
                <p class="sk_goods_price"><em>¥${ele.current_price}</em> <del>￥${ele.price}</del></p>
                <div class="sk_goods_progress">
                    已售<i>${ele.sale_type}</i>
                    <div class="bar">
                        <div class="bar_in"></div>
                    </div>
                    剩余<em>${ele.goods_number}</em>件
                </div>
                <a href="detail.html?id=${ele.goods_id}" class="sk_goods_buy">立即抢购</a>
            </li>`
                });
            }
            this.$('.sk_bd ul').innerHTML = html
        })
    }

    // 判断登录状态 设置用户名
    loginStatus() {
        let status = localStorage.getItem('id')
        let username = localStorage.getItem('uname')
        console.log(this.$('.fr li a')[0]);
        if (status) {
            this.$('.f10').forEach(ele => {
                this.$('.fr li a')[0].innerHTML = username
            })
        }
    }
    // 封装获取节点的方法
    $(ele) {
        let res = document.querySelectorAll(ele);
        return res.length == 1 ? res[0] : res;
    }
}
new List